package com.ciccwm.dubbo.service;

import com.ciccwm.dubbo.api.entity.DubboTest;
import com.ciccwm.dubbo.api.service.DubboTestService;
import com.ciccwm.msg.api.DubboMsgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
import org.apache.shenyu.client.apidocs.annotations.ApiModule;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.common.utils.GsonUtils;

import java.util.Random;

/**
 * The type Dubbo service.
 */
@Slf4j
@DubboService
@ApiModule(value = "dubboTestService")
public class DubboTestServiceImpl implements DubboTestService {

    @DubboReference
    private DubboMsgService dubboMsgService;

    @Override
    @ShenyuDubboClient("/findById")
    @ApiDoc(desc = "findById")
    public DubboTest findById(final String id) {
        log.info(GsonUtils.getInstance().toJson(RpcContext.getContext().getAttachments()));
        String msgId = dubboMsgService.sendMsg(id);
        return new DubboTest(id, "msgId:" + msgId);
    }
}
